package com.test.demo;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.UnsupportedCharsetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.CharUtils;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.junit.Test;

import com.alibaba.fastjson.JSON;

/**   
 * @ClassName:     Demo   
 * @Description:   湖南竞网客服系统接口demo
 * @author:        wl
 * @date:          2018年3月5日 上午10:38:57     
 */  
public class Demo {
	
	/**   
	 * @Title:         获取票据接口   
	 * @Description:   open/platform/getAccessToken接口
	 * @param:               
	 * @return:        void   
	 * @author:        wl  
	 * @date:          2018年3月5日 上午11:08:54   
	 * @throws   
	 */  
	@Test
	public void accessToken(){
		Map head = new HashMap();
		Map params = new HashMap();
		//固定值【必填】
		params.put("version", "1.0");
		//平台注册的appID,由智齿提供，固定值【必填】
		params.put("appId", "100000002");
		//请求时间戳【必填】
		params.put("createTime", new Date().getTime()/1000+"");
		//有效期时间【必填】
		params.put("expire ", 7200+"");
		//appid+appkey+createTime的md5值【32位小写值】【必填】
		params.put("sign", DigestUtils.md5Hex("100000002"+"sobot"+params.get("createTime")));
		clientPost("http://imapi.cic.open.ejw.cn/open/platform/getAccessToken", head, params);
		System.out.println(JSON.toJSONString(params));
		//返回值如下：{"code":"1000","data":{"access_token":"444aa1c5276941b9b352dac962f28af0"}}
		//说明：code：1000返回正确，1001参数错误，access_token为返回的票据信息，用于获取token值。
	}
	
	/**   
	 * @Title:         获取token接口   
	 * @Description:   open/platform/api接口 
	 * @param:               
	 * @return:        void   
	 * @author:        wl  
	 * @date:          2018年3月5日 上午11:09:53   
	 * @throws   
	 */  
	@Test
	public void getToken(){
		Map params = new HashMap();
		//固定值【必填】
		params.put("action", "console_direct_url");
		//access_token为open/platform/getAccessToken返回的access_token值【必填】
		params.put("access_token", "7fb8ed0523914cbd8b2872248dbaa3b4");
		Map data = new HashMap();
		//email为登陆用户的邮箱【必填】
		data.put("email", "hudapeng423@163.com");
		params.put("data", data);
		System.out.println(
				HttpClientPost("http://imapi.cic.open.ejw.cn/open/platform/api", JSON.toJSONString(params))
//				HttpClientPost("http://sobot.com/open/platform/api", JSON.toJSONString(params))
				);
		//返回值说明：{"code":"1000","data":{"temp-id":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdXBlckBzb2JvdC5jb20iLCJleHAiOjE1MjAzOTI0OTl9.DESdDeLxBCNB_XmeP43c-z48CYYNdcMzTb4kG5No9iw","url":"http://imapi.cic.open.ejw.cn/console/openAPI/login/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdXBlckBzb2JvdC5jb20iLCJleHAiOjE1MjAzOTI0OTl9.DESdDeLxBCNB_XmeP43c-z48CYYNdcMzTb4kG5No9iw"}}
		//code：1000请求成功,1001请求失败,temp-id：请求其他鉴权接口需要的token值，url：单点登录地址
	}
	
	/**   
	 * @Title:         添加客服接口   【管理员与超级管理员可添加客服】
	 * @Description:   addserviceInfoConfim/4接口  
	 * @param:               
	 * @return:        void   
	 * @author:        wl  
	 * @date:          2018年3月5日 下午2:13:29   
	 * @throws   
	 */  
	@Test
	public void addServiceInfo(){
		Map head = new HashMap();
		//getToken接口获取的参数
		head.put("temp-id", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIxNTYwMDQ0MjcxOUAxNjMuY29tIiwiZXhwIjoxNTIxMDAwMTAxfQ.FIoCDW8yvziAVnIqgM3RPFR7eBBNJi_EHToYavNJ3wE");
		Map params = new HashMap();
		//客服邮箱【必填】
		params.put("email", "test009@sobot.com");
		//客服昵称【必填】
		params.put("nick", "测试昵称");
		//客服姓名【必填】
		params.put("name", "测试姓名");
		//客服角色【固定值】【必填】1111 在线客服,2222 管理员
		params.put("cusRoleId", "1111");
		//客服角色名称【固定值】【必填】
		params.put("cusRoleName", "在线客服");
		//客服员工编号【选填】
//		params.put("ServiceNo", "10000000000017");
//		clientPost("http://imapi.cic.open.ejw.cn/basic/addserviceInfoConfim/4", head, params);	
		clientPost("http://sobot.com/basic/addserviceInfoConfim/4", head, params);	
		//返回值说明：{"items":[],"retCode":"000000"}，{"items":[],"retCode":"100008","retMsg":"参数不正确"}
		//retCode：000000返回成功，retMsg：返回错误信息
	}
	
	/**   
	 * @Title:         查询客服信息接口   
	 * @Description:   basic/queryCusServiceInfo/4   接口
	 * @param:               
	 * @return:        void   
	 * @author:        wl  
	 * @date:          2018年3月5日 下午2:27:27   
	 * @throws   
	 */  
	@Test
	public void queryCusServiceInfo(){
		Map head = new HashMap();
		//getToken接口获取的参数
		head.put("temp-id", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZXN0MDAxQHNvYm90LmNvbSIsImV4cCI6MTUyMDM5NTA0MX0.ZmLFyTP6rVftStd3vC0b6c_tYo4HD4rIkKgXQBzjxZY");
		Map params = new HashMap();		
		//客服ID【必填】
		params.put("serviceId", "989121506e864ca09ece00591e41f70b");
		System.out.println(
				HttpsClientGet("http://imapi.cic.open.ejw.cn/basic/queryCusServiceInfo/4", head, params)
				);
		//返回值说明：{"item":{"groupMap":{},"perInfo":{"jurisdiction":"1","serviceInfo":{"companyId":"85a70b5ec76f4d0397c54348c4e98b27","createServiceId":"4fe06af4fa3949e6b140ccd0f89789ed","createTime":1517822166,"cusRoleId":"1111","cusRoleName":"在线客服","docStatus":1,"effectTime":1517822166,"faceImg":"https://img.sobot.com/console/common/face/admin.png","imFlag":1,"invalidTime":1798732799,"lastLoginTime":1520221670,"lockFlag":0,"loginStatus":1,"loginTime":1520228829,"maxAccept":10,"replyAuthFlag":0,"serviceEmail":"wang002@stnts.com","serviceId":"21c47dc154574184bdc6ea5cc3074495","serviceName":"测试姓名02","serviceNick":"测试02","serviceStatus":1,"ticketAuthFlag":0,"updateTime":1518159219},"show":"1"},"serviceVo":{"accountStatus":2,"centerNumber":"","companyCreateTime":1517458370,"companyId":"85a70b5ec76f4d0397c54348c4e98b27","companyName":"测试账号","completeFlag":1,"cusRoleId":"3333","cusRoleName":"超级管理员","docStatus":0,"faceImg":"https://img.sobot.com/console/common/face/admin.png","fileSize":102400,"functionStr":[{"checked":true,"id":"1101","name":"我的工单","open":true,"pId":"11"},{"checked":true,"id":"24","name":"短信","open":true,"pId":"0"},{"checked":true,"id":"1102","name":"我的接待","open":true,"pId":"11"},{"checked":true,"id":"1901","name":"机器人信息","open":true,"pId":"19"},{"checked":true,"id":"13011","name":"小智机器人","open":true,"pId":"1301"},{"checked":true,"id":"1301","name":"机器人","open":true,"pId":"13"},{"checked":true,"id":"1501","name":"工单客服","open":true,"pId":"15"},{"checked":true,"id":"1601","name":"客户列表","open":true,"pId":"16"},{"checked":true,"id":"1701","name":"访问分析","open":true,"pId":"17"},{"checked":true,"id":"2201","name":"登录工作台","open":true,"pId":"22"},{"checked":true,"id":"220201","name":"拉黑用户","open":true,"pId":"2202"},{"checked":true,"id":"1801","name":"在线会话质检","open":true,"pId":"18"},{"checked":true,"id":"2401","name":"我的短信记录","open":true,"pId":"24"},{"checked":true,"id":"11","name":"console首页","open":true,"pId":"0"},{"checked":true,"id":"1103","name":"客服概况","open":true,"pId":"11"},{"checked":true,"id":"1902","name":"上下班时间设置","open":true,"pId":"19"},{"checked":true,"id":"12","name":"工单中心","open":true,"pId":"0"},{"checked":true,"id":"1502","name":"在线客服","open":true,"pId":"15"},{"checked":true,"id":"1602","name":"公司列表","open":true,"pId":"16"},{"checked":true,"id":"1702","name":"客服工作量","open":true,"pId":"17"},{"checked":true,"id":"2202","name":"用户管理","open":true,"pId":"22"},{"checked":true,"id":"220202","name":" 转接","open":true,"pId":"2202"},{"checked":true,"id":"1802","name":"在线客服得分","open":true,"pId":"18"},{"checked":true,"id":"2402","name":"所有短信记录","open":true,"pId":"24"},{"checked":true,"id":"1903","name":"自定义字段","open":true,"pId":"19"},{"checked":true,"id":"13","name":"知识库","open":true,"pId":"0"},{"checked":true,"id":"1303","name":"内部知识库编辑","open":true,"pId":"13"},{"checked":true,"id":"1503","name":"管理员","open":true,"pId":"15"},{"checked":true,"id":"1703","name":"会话记录","open":true,"pId":"17"},{"checked":true,"id":"220203","name":"邀请新用户","open":true,"pId":"2202"},{"checked":true,"id":"2203","name":"管理公共快捷回复","open":true,"pId":"22"},{"checked":true,"id":"1803","name":"在线会话质检记录","open":true,"pId":"18"},{"checked":true,"id":"2403","name":"短信模板管理","open":true,"pId":"24"},{"checked":true,"id":"1904","name":"SLA服务目标","open":true,"pId":"19"},{"checked":true,"id":"1304","name":"内部知识库查询","open":true,"pId":"13"},{"checked":true,"id":"1504","name":"工单客服组","open":true,"pId":"15"},{"checked":true,"id":"1704","name":"满意度评价","open":true,"pId":"17"},{"checked":true,"id":"220204","name":"个性化自动应答说辞","open":true,"pId":"2202"},{"checked":true,"id":"1905","name":"桌面网站","open":true,"pId":"19"},{"checked":true,"id":"15","name":"客服和组","open":true,"pId":"0"},{"checked":true,"id":"1505","name":"在线技能组","open":true,"pId":"15"},{"checked":true,"id":"1705","name":"工单统计概览","open":true,"pId":"17"},{"checked":true,"id":"1906","name":"移动网站","open":true,"pId":"19"},{"checked":true,"id":"16","name":"客户中心","open":true,"pId":"0"},{"checked":true,"id":"1706","name":"机器人回答","open":true,"pId":"17"},{"checked":true,"id":"1907","name":"APP","open":true,"pId":"19"},{"checked":true,"id":"17","name":"统计","open":true,"pId":"0"},{"checked":true,"id":"1707","name":"用户反馈","open":true,"pId":"17"},{"checked":true,"id":"1908","name":"微信","open":true,"pId":"19"},{"checked":true,"id":"1708","name":"维护工作量","open":true,"pId":"17"},{"checked":true,"id":"18","name":"质检","open":true,"pId":"0"},{"checked":true,"id":"19","name":"设置","open":true,"pId":"0"},{"checked":true,"id":"1909","name":"第三方平台","open":true,"pId":"19"},{"checked":true,"id":"1910","name":"客服工作台","open":true,"pId":"19"},{"checked":true,"id":"1911","name":"在线客服分配","open":true,"pId":"19"},{"checked":true,"id":"21","name":"消息中心","open":true,"pId":"0"},{"checked":true,"id":"1912","name":"会话自动应答","open":true,"pId":"19"},{"checked":true,"id":"22","name":"客服工作台","open":true,"pId":"0"},{"checked":true,"id":"1913","name":"留言设置","open":true,"pId":"19"},{"checked":true,"id":"1914","name":"在线质检评分标准","open":true,"pId":"19"},{"checked":true,"id":"1915","name":"呼叫中心状态","open":true,"pId":"19"},{"checked":true,"id":"1716","name":"客户来源统计","open":true,"pId":"17"},{"checked":true,"id":"1717","name":"搜索词统计","open":true,"pId":"17"},{"checked":true,"id":"1718","name":"受访面统计","open":true,"pId":"17"},{"checked":true,"id":"1919","name":"对接页面","open":true,"pId":"19"},{"checked":true,"id":"1719","name":"入口页面统计","open":true,"pId":"17"},{"checked":true,"id":"1920","name":"工单设置","open":true,"pId":"19"},{"checked":true,"id":"1720","name":"对话页面统计","open":true,"pId":"17"},{"checked":true,"id":"1921","name":"监控告警","open":true,"pId":"19"},{"checked":true,"id":"1721","name":"智能报表","open":true,"pId":"17"},{"checked":true,"id":"1922","name":"客服账户","open":true,"pId":"19"},{"checked":true,"id":"1722","name":"客服工作量","open":true,"pId":"17"},{"checked":true,"id":"1923","name":"权限管理","open":true,"pId":"19"},{"checked":true,"id":"1723","name":"工单分类统计","open":true,"pId":"17"},{"checked":true,"id":"1925","name":"关键词屏蔽","open":true,"pId":"19"},{"checked":true,"id":"1926","name":"智能优化策略","open":true,"pId":"19"},{"checked":true,"id":"1927","name":"客服状态自定义","open":true,"pId":"19"},{"checked":true,"id":"1928","name":"人工满意度评价设置","open":true,"pId":"19"},{"checked":true,"id":"1929","name":"强制下线","open":true,"pId":"19"},{"checked":true,"id":"1930","name":"编辑公共快捷方式","open":true,"pId":"19"},{"checked":true,"id":"1931","name":"微博","open":true,"pId":"19"}],"imFlag":1,"imNum":20,"inviteCode":"","isOnGroup":"1","lastLoginTime":1520220587,"maxAccept":10,"orgRoleId":"","phoneNo":"18611783477","replyAuthFlag":0,"robotNum":1,"secondDomain":"","serviceEmail":"super@sobot.com","serviceId":"8378b9ede5864c0da3dab0abd818dafb","serviceName":"超级管理员","serviceNick":"超级管理员","serviceStatus":1,"servicerNum":2004,"supportEmail":"super@sobot.com","systemNum":"85a70b5ec76f4d0397c54348c4e98b27","ti":"vgDBz6pJwi1k1_zBmxayHx-SixnZgUz9uuuSsyUWUoA","ticketAuthFlag":0,"unionCode":"019"}},"items":[],"retCode":"000000"}
		//retCode：000000返回成功，retMsg：返回错误信息，serviceInfo：客服信息
		//serviceInfo说明：companyId : 公司ID，createServiceId : "创建客服的用户ID"，createTime : "创建时间"，cusRoleId : "用户角色"，cusRoleName : "用户角色名称"，faceImg : "头像地址"，loginStatus : "登陆状态"，loginTime : "登陆时间"，maxAccept : "最大接待数"，serviceEmail : "客服邮箱"，serviceId : "客服id"，serviceName : "客服名称"，serviceNick : "客服昵称"，serviceStatus : "客服状态".【注：其他参数用不到的不用理会】
	}
	
	/**   
	 * @Title:         修改用户接口【管理员与超级管理员有此权限】   
	 * @Description:   basic/updateServiceInfo/4  
	 * @param:               
	 * @return:        void   
	 * @author:        wl  
	 * @date:          2018年3月6日 上午10:19:10   
	 * @throws   
	 */  
	@Test
	public void updateServiceInfo(){
		Map head = new HashMap();
		//getToken接口获取的参数
		head.put("temp-id", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZXN0MDAxQHNvYm90LmNvbSIsImV4cCI6MTUyMDM5NTA0MX0.ZmLFyTP6rVftStd3vC0b6c_tYo4HD4rIkKgXQBzjxZY");
		Map params = new HashMap();	
		//客服昵称【选填】
//		params.put("serviceNick", "测");
		//客服姓名【选填】
//		params.put("serviceName", "测");
		//手机号【选填】
//		params.put("phoneNo", "");
		//电话号【选填】
//		params.put("telephoneNo", "");
		//QQ号【选填】
//		params.put("serviceQQ", "");
		//备注【选填】
//		params.put("serviceRemark", "");
		//最大接待数【选填】
//		params.put("maxAccept", "");
		//组id【选填】
//		params.put("groupIds", "");
		//角色id【固定值】【选填】
//		params.put("cusRoleId", "1111");
		//角色名称【固定值】【选填】
//		params.put("cusRoleName", "在线客服");
		//客服id【必填】
		params.put("serviceId", "989121506e864ca09ece00591e41f70b");
		clientPost("http://imapi.cic.open.ejw.cn/basic/updateServiceInfo/4", head, params);
		//返回参数说明：{"items":[],"retCode":"000000"}
		//retCode：000000返回正确，retMsg：错误描述
	}
	
	/**   
	 * @Title:         删除客服信息接口   【管理员与超级管理员有此权限】   
	 * @Description:   basic/deleteCusServiceInfo/4  
	 * @param:               
	 * @return:        void   
	 * @author:        wl  
	 * @date:          2018年3月6日 上午10:24:49   
	 * @throws   
	 */  
	@Test
	public void deleteCusServiceInfo(){
		Map head = new HashMap();
		//getToken接口获取的参数
		head.put("temp-id", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZXN0MDAxQHNvYm90LmNvbSIsImV4cCI6MTUyMDM5NTA0MX0.ZmLFyTP6rVftStd3vC0b6c_tYo4HD4rIkKgXQBzjxZY");
		Map params = new HashMap();		
		//角色ID【必填】1111 在线客服,2222 管理员
		params.put("cusRoleId", "1111");
		//客服ID【必填】
		params.put("serviceId", "989121506e864ca09ece00591e41f70b");
		clientPost("http://imapi.cic.open.ejw.cn/basic/deleteCusServiceInfo/4",head,params);
		//返回值说明：{"items":[],"retCode":"000000"}
		//retCode:000000返回成功，retMsg：错误描述
	}
	
	/**   
	 * @Title:         查询客服信息列表   
	 * @Description:   basic/queryDiffRoleCusServiceInfoList/4   
	 * @param:               
	 * @return:        void   
	 * @author:        wl  
	 * @date:          2018年3月6日 上午10:25:54   
	 * @throws   
	 */  
	@Test
	public void queryDiffRoleCusServiceInfoList(){
		Map head = new HashMap();
		//getToken接口获取的参数
		head.put("temp-id", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJ0ZXN0MDAxQHNvYm90LmNvbSIsImV4cCI6MTUyMDY2MTY3Mn0.3FA4RnwALCdRE0WUy_DTEg_B0c1kk5nHpKbNU0p5t4A");
		Map params = new HashMap();
		//固定值，1为在线，2为管理员【必填】
		params.put("flag", "1");
		//组ID【选填】
//		params.put("groupId", "");
		//页数【必填】
		params.put("pageNo", "1");
		//页码数【必填】
		params.put("pageSize", "10");
		//角色ID【选填】
//		params.put("roleId", "");
		//查询员工编号【选填】		
//		params.put("serviceNo", "100000000000");
		//查询客服真实姓名【选填】
//		params.put("serviceName", "真实");
		//查询客服昵称【选填】
//		params.put("serviceNick", "测试");
		//客服状态，固定值100：所有客服状态【必填】
		params.put("serviceStatus", "100");
		System.out.println(
				HttpsClientGet("http://imapi.cic.open.ejw.cn/basic/queryDiffRoleCusServiceInfoList/4", head, params)
				);
		//返回值说明：{"item":{"serviceStatus1":15,"serviceVo":{"accountStatus":2,"centerNumber":"","companyCreateTime":1517458370,"companyId":"85a70b5ec76f4d0397c54348c4e98b27","companyName":"测试账号","completeFlag":1,"cusRoleId":"3333","cusRoleName":"超级管理员","docStatus":0,"faceImg":"https://img.sobot.com/console/common/face/admin.png","fileSize":102400,"functionStr":[{"checked":true,"id":"24","name":"短信","open":true,"pId":"0"},{"checked":true,"id":"1101","name":"我的工单","open":true,"pId":"11"},{"checked":true,"id":"13011","name":"小智机器人","open":true,"pId":"1301"},{"checked":true,"id":"1301","name":"机器人","open":true,"pId":"13"},{"checked":true,"id":"1501","name":"工单客服","open":true,"pId":"15"},{"checked":true,"id":"1601","name":"客户列表","open":true,"pId":"16"},{"checked":true,"id":"1701","name":"访问分析","open":true,"pId":"17"},{"checked":true,"id":"2201","name":"登录工作台","open":true,"pId":"22"},{"checked":true,"id":"220201","name":"拉黑用户","open":true,"pId":"2202"},{"checked":true,"id":"1801","name":"在线会话质检","open":true,"pId":"18"},{"checked":true,"id":"2401","name":"我的短信记录","open":true,"pId":"24"},{"checked":true,"id":"11","name":"console首页","open":true,"pId":"0"},{"checked":true,"id":"1102","name":"我的接待","open":true,"pId":"11"},{"checked":true,"id":"1901","name":"机器人信息","open":true,"pId":"19"},{"checked":true,"id":"1502","name":"在线客服","open":true,"pId":"15"},{"checked":true,"id":"1602","name":"公司列表","open":true,"pId":"16"},{"checked":true,"id":"1702","name":"客服工作量","open":true,"pId":"17"},{"checked":true,"id":"2202","name":"用户管理","open":true,"pId":"22"},{"checked":true,"id":"220202","name":" 转接","open":true,"pId":"2202"},{"checked":true,"id":"1802","name":"在线客服得分","open":true,"pId":"18"},{"checked":true,"id":"2402","name":"所有短信记录","open":true,"pId":"24"},{"checked":true,"id":"1103","name":"客服概况","open":true,"pId":"11"},{"checked":true,"id":"1902","name":"上下班时间设置","open":true,"pId":"19"},{"checked":true,"id":"12","name":"工单中心","open":true,"pId":"0"},{"checked":true,"id":"1303","name":"内部知识库编辑","open":true,"pId":"13"},{"checked":true,"id":"1503","name":"管理员","open":true,"pId":"15"},{"checked":true,"id":"1703","name":"会话记录","open":true,"pId":"17"},{"checked":true,"id":"220203","name":"邀请新用户","open":true,"pId":"2202"},{"checked":true,"id":"2203","name":"管理公共快捷回复","open":true,"pId":"22"},{"checked":true,"id":"1803","name":"在线会话质检记录","open":true,"pId":"18"},{"checked":true,"id":"2403","name":"短信模板管理","open":true,"pId":"24"},{"checked":true,"id":"1903","name":"自定义字段","open":true,"pId":"19"},{"checked":true,"id":"13","name":"知识库","open":true,"pId":"0"},{"checked":true,"id":"1304","name":"内部知识库查询","open":true,"pId":"13"},{"checked":true,"id":"1504","name":"工单客服组","open":true,"pId":"15"},{"checked":true,"id":"1704","name":"满意度评价","open":true,"pId":"17"},{"checked":true,"id":"220204","name":"个性化自动应答说辞","open":true,"pId":"2202"},{"checked":true,"id":"1904","name":"SLA服务目标","open":true,"pId":"19"},{"checked":true,"id":"15","name":"客服和组","open":true,"pId":"0"},{"checked":true,"id":"1505","name":"在线技能组","open":true,"pId":"15"},{"checked":true,"id":"1705","name":"工单统计概览","open":true,"pId":"17"},{"checked":true,"id":"1905","name":"桌面网站","open":true,"pId":"19"},{"checked":true,"id":"1906","name":"移动网站","open":true,"pId":"19"},{"checked":true,"id":"16","name":"客户中心","open":true,"pId":"0"},{"checked":true,"id":"1706","name":"机器人回答","open":true,"pId":"17"},{"checked":true,"id":"1907","name":"APP","open":true,"pId":"19"},{"checked":true,"id":"17","name":"统计","open":true,"pId":"0"},{"checked":true,"id":"1707","name":"用户反馈","open":true,"pId":"17"},{"checked":true,"id":"1908","name":"微信","open":true,"pId":"19"},{"checked":true,"id":"1708","name":"维护工作量","open":true,"pId":"17"},{"checked":true,"id":"18","name":"质检","open":true,"pId":"0"},{"checked":true,"id":"1909","name":"第三方平台","open":true,"pId":"19"},{"checked":true,"id":"19","name":"设置","open":true,"pId":"0"},{"checked":true,"id":"1910","name":"客服工作台","open":true,"pId":"19"},{"checked":true,"id":"1911","name":"在线客服分配","open":true,"pId":"19"},{"checked":true,"id":"21","name":"消息中心","open":true,"pId":"0"},{"checked":true,"id":"1912","name":"会话自动应答","open":true,"pId":"19"},{"checked":true,"id":"22","name":"客服工作台","open":true,"pId":"0"},{"checked":true,"id":"1913","name":"留言设置","open":true,"pId":"19"},{"checked":true,"id":"1914","name":"在线质检评分标准","open":true,"pId":"19"},{"checked":true,"id":"1915","name":"呼叫中心状态","open":true,"pId":"19"},{"checked":true,"id":"1716","name":"客户来源统计","open":true,"pId":"17"},{"checked":true,"id":"1717","name":"搜索词统计","open":true,"pId":"17"},{"checked":true,"id":"1718","name":"受访面统计","open":true,"pId":"17"},{"checked":true,"id":"1919","name":"对接页面","open":true,"pId":"19"},{"checked":true,"id":"1719","name":"入口页面统计","open":true,"pId":"17"},{"checked":true,"id":"1920","name":"工单设置","open":true,"pId":"19"},{"checked":true,"id":"1720","name":"对话页面统计","open":true,"pId":"17"},{"checked":true,"id":"1921","name":"监控告警","open":true,"pId":"19"},{"checked":true,"id":"1721","name":"智能报表","open":true,"pId":"17"},{"checked":true,"id":"1922","name":"客服账户","open":true,"pId":"19"},{"checked":true,"id":"1722","name":"客服工作量","open":true,"pId":"17"},{"checked":true,"id":"1923","name":"权限管理","open":true,"pId":"19"},{"checked":true,"id":"1723","name":"工单分类统计","open":true,"pId":"17"},{"checked":true,"id":"1925","name":"关键词屏蔽","open":true,"pId":"19"},{"checked":true,"id":"1926","name":"智能优化策略","open":true,"pId":"19"},{"checked":true,"id":"1927","name":"客服状态自定义","open":true,"pId":"19"},{"checked":true,"id":"1928","name":"人工满意度评价设置","open":true,"pId":"19"},{"checked":true,"id":"1929","name":"强制下线","open":true,"pId":"19"},{"checked":true,"id":"1930","name":"编辑公共快捷方式","open":true,"pId":"19"},{"checked":true,"id":"1931","name":"微博","open":true,"pId":"19"}],"imFlag":1,"imNum":20,"inviteCode":"","isOnGroup":"1","lastLoginTime":1520303504,"maxAccept":10,"orgRoleId":"","phoneNo":"18611783477","replyAuthFlag":0,"robotNum":1,"secondDomain":"","serviceEmail":"super@sobot.com","serviceId":"8378b9ede5864c0da3dab0abd818dafb","serviceName":"超级管理员","serviceNick":"超级管理员","serviceStatus":1,"servicerNum":2004,"supportEmail":"super@sobot.com","systemNum":"85a70b5ec76f4d0397c54348c4e98b27","ti":"DESdDeLxBCNB_XmeP43c-z48CYYNdcMzTb4kG5No9iw","ticketAuthFlag":0,"unionCode":"019"}},"items":[{"companyId":"85a70b5ec76f4d0397c54348c4e98b27","createServiceId":"8378b9ede5864c0da3dab0abd818dafb","createTime":1520306238,"cusRoleId":"1111","cusRoleName":"在线客服","docStatus":1,"faceImg":"https://img.sobot.com/console/common/face/admin.png","imFlag":1,"invalidTime":1798732799,"lockFlag":0,"maxAccept":10,"replyAuthFlag":0,"robotDocAuthFlag":0,"serviceEmail":"test008@sobot.com","serviceId":"989121506e864ca09ece00591e41f70b","serviceName":"测试姓名","serviceNick":"测试昵称","serviceStatus":1,"ticketAuthFlag":0,"ticketDocAuthFlag":0,"updateTime":1520306238,"userAuthFlag":0},{"companyId":"85a70b5ec76f4d0397c54348c4e98b27","createServiceId":"8378b9ede5864c0da3dab0abd818dafb","createTime":1520231021,"cusRoleId":"1111","cusRoleName":"在线客服","docStatus":1,"faceImg":"https://img.sobot.com/console/common/face/admin.png","imFlag":1,"invalidTime":1798732799,"lockFlag":0,"maxAccept":10,"replyAuthFlag":0,"robotDocAuthFlag":0,"serviceEmail":"test006@sobot.com","serviceId":"402a9c6410dd4d87848c0f69ed382fb5","serviceName":"测试姓名","serviceNick":"测试昵称","serviceNo":"10000000000016","serviceStatus":1,"ticketAuthFlag":0,"ticketDocAuthFlag":0,"updateTime":1520231021,"userAuthFlag":0},{"companyId":"85a70b5ec76f4d0397c54348c4e98b27","createServiceId":"8378b9ede5864c0da3dab0abd818dafb","createTime":1520216392,"cusRoleId":"1111","cusRoleName":"????","docStatus":1,"faceImg":"https://img.sobot.com/console/common/face/admin.png","imFlag":1,"invalidTime":1798732799,"lockFlag":0,"maxAccept":10,"replyAuthFlag":0,"robotDocAuthFlag":0,"serviceEmail":"zhanghongjun@hnjing.com","serviceId":"ce66366035d14941b556ae6a0d687479","serviceName":"string","serviceNick":"string","serviceNo":"string","serviceStatus":1,"ticketAuthFlag":0,"ticketDocAuthFlag":0,"updateTime":1520216392,"userAuthFlag":0},{"companyId":"85a70b5ec76f4d0397c54348c4e98b27","createServiceId":"8378b9ede5864c0da3dab0abd818dafb","createTime":1520216139,"cusRoleId":"1111","cusRoleName":"在线客服","docStatus":1,"faceImg":"https://img.sobot.com/console/common/face/admin.png","imFlag":1,"invalidTime":1798732799,"lockFlag":0,"maxAccept":10,"replyAuthFlag":0,"robotDocAuthFlag":0,"serviceEmail":"test005@sobot.com","serviceId":"825f2c09f3f143eaaa1892dc40b50a53","serviceName":"真实姓名","serviceNick":"联调测试","serviceNo":"10000000000015","serviceStatus":1,"ticketAuthFlag":0,"ticketDocAuthFlag":0,"updateTime":1520216139,"userAuthFlag":0},{"companyId":"85a70b5ec76f4d0397c54348c4e98b27","createServiceId":"8378b9ede5864c0da3dab0abd818dafb","createTime":1520212814,"cusRoleId":"1111","cusRoleName":"????","docStatus":1,"faceImg":"https://img.sobot.com/console/common/face/admin.png","imFlag":1,"invalidTime":1798732799,"lockFlag":0,"maxAccept":10,"replyAuthFlag":0,"robotDocAuthFlag":0,"serviceEmail":"zhangweicheng@hnjing.com","serviceId":"bedd1ee18529442a8eed55fe22949f97","serviceName":"string","serviceNick":"string","serviceNo":"string","serviceStatus":1,"ticketAuthFlag":0,"ticketDocAuthFlag":0,"updateTime":1520212814,"userAuthFlag":0},{"companyId":"85a70b5ec76f4d0397c54348c4e98b27","createServiceId":"8378b9ede5864c0da3dab0abd818dafb","createTime":1519962752,"cusRoleId":"1111","cusRoleName":"在线客服","docStatus":1,"faceImg":"https://img.sobot.com/console/common/face/admin.png","imFlag":1,"invalidTime":1798732799,"lockFlag":0,"maxAccept":10,"replyAuthFlag":0,"robotDocAuthFlag":0,"serviceEmail":"test004@sobot.com","serviceId":"0f0aee38c1ee41aabf9c2c663d635c03","serviceName":"真实姓名","serviceNick":"联调测试","serviceNo":"10000000000014","serviceStatus":1,"ticketAuthFlag":0,"ticketDocAuthFlag":0,"updateTime":1519962752,"userAuthFlag":0},{"companyId":"85a70b5ec76f4d0397c54348c4e98b27","createServiceId":"8378b9ede5864c0da3dab0abd818dafb","createTime":1519962676,"cusRoleId":"1111","cusRoleName":"在线客服","docStatus":1,"faceImg":"https://img.sobot.com/console/common/face/admin.png","imFlag":1,"invalidTime":1798732799,"lockFlag":0,"maxAccept":10,"replyAuthFlag":0,"robotDocAuthFlag":0,"serviceEmail":"test003@sobot.com","serviceId":"3c29c66197b3459da5c69e647c0aff67","serviceName":"真实姓名","serviceNick":"联调测试","serviceNo":"10000000000013","serviceStatus":1,"ticketAuthFlag":0,"ticketDocAuthFlag":0,"updateTime":1519962676,"userAuthFlag":0},{"companyId":"85a70b5ec76f4d0397c54348c4e98b27","createServiceId":"8378b9ede5864c0da3dab0abd818dafb","createTime":1519958366,"cusRoleId":"1111","cusRoleName":"在线客服","docStatus":1,"faceImg":"https://img.sobot.com/console/common/face/admin.png","imFlag":1,"invalidTime":1798732799,"lockFlag":0,"maxAccept":10,"replyAuthFlag":0,"robotDocAuthFlag":0,"serviceEmail":"test002@sobot.com","serviceId":"e60f3d269a3b46e1aab59d5da8f637be","serviceName":"真实姓名","serviceNick":"联调测试","serviceNo":"10000000000012","serviceStatus":1,"ticketAuthFlag":0,"ticketDocAuthFlag":0,"updateTime":1519958366,"userAuthFlag":0},{"companyId":"85a70b5ec76f4d0397c54348c4e98b27","createServiceId":"8378b9ede5864c0da3dab0abd818dafb","createTime":1519957729,"cusRoleId":"1111","cusRoleName":"在线客服","docStatus":1,"faceImg":"https://img.sobot.com/console/common/face/admin.png","imFlag":1,"invalidTime":1798732799,"lockFlag":0,"maxAccept":10,"replyAuthFlag":0,"robotDocAuthFlag":0,"serviceEmail":"test001@sobot.com","serviceId":"fc6813641f7b4661b9d8be988214fa7c","serviceName":"真实姓名","serviceNick":"联调测试","serviceNo":"10000000000011","serviceStatus":1,"ticketAuthFlag":0,"ticketDocAuthFlag":0,"updateTime":1519957729,"userAuthFlag":0},{"companyId":"85a70b5ec76f4d0397c54348c4e98b27","createServiceId":"8378b9ede5864c0da3dab0abd818dafb","createTime":1519956376,"cusRoleId":"1111","cusRoleName":"????","docStatus":1,"faceImg":"https://img.sobot.com/console/common/face/admin.png","imFlag":1,"invalidTime":1798732799,"lockFlag":0,"maxAccept":10,"replyAuthFlag":0,"robotDocAuthFlag":0,"serviceEmail":"lijianbing@hnjing.com","serviceId":"db9689c178884f2bb9b38e95a05a02ff","serviceName":"string","serviceNick":"string","serviceNo":"string","serviceStatus":1,"ticketAuthFlag":0,"ticketDocAuthFlag":0,"updateTime":1519956376,"userAuthFlag":0}],"pageCount":2,"pageNo":1,"retCode":"000000","totalCount":15}
		//retCode:000000返回成功，retMsg：错误描述，pageNo : 页码，pageCount : 页数，totalCount : 条数，items：客服信息列表
	}
	
	/**   
	 * @Title:         客服在线状态   
	 * @Description:   chat/admin/getAdminStatus.action  
	 * @param:               
	 * @return:        void   
	 * @author:        wl  
	 * @date:          2018年3月6日 上午10:28:33   
	 * @throws   
	 */  
	@Test
	public void getAdminStatus(){
		Map head = new HashMap();
		//getToken接口获取的参数
		head.put("temp-id", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdXBlckBzb2JvdC5jb20iLCJleHAiOjE1MjAzOTI0OTl9.DESdDeLxBCNB_XmeP43c-z48CYYNdcMzTb4kG5No9iw");
		Map params = new HashMap();		
		clientPost("http://imapi.cic.open.ejw.cn/chat/admin/getAdminStatus.action", head, params);
		//返回值说明：{"items":[],"retCode":"999999","retMsg":"客服未登陆工作台"}
		//retCode:000000返回成功，retMsg：错误描述,status:客服状态码【0：离线，1：在线，2：忙碌】
	}
	
	public static void clientPost(String url,Map head,Map params){
		System.out.println(
				HttpClientPost(url, head, params)
				);			
	}
	
	public static String HttpClientPost(String address,String params){
		StringBuilder builder = null;
		try {
			HttpClient client = HttpClients.createDefault();
			RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();
			HttpPost httpPost = new HttpPost(address);
			httpPost.setConfig(requestConfig);
			StringEntity entity = new StringEntity(params,"UTF-8");
			entity.setContentEncoding("UTF-8");
			entity.setContentType("application/json");
			httpPost.setEntity(entity);	
			HttpResponse response = client.execute(httpPost);
			builder = new StringBuilder();
			builder.append(new String(getByte(response.getEntity().getContent()),"UTF-8"));
		} catch (UnsupportedCharsetException e) {
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (UnsupportedOperationException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return builder.toString();
	}
	
	public static String HttpClientPost(String address,Map<String,String> head,Map<String,String> params){
		StringBuilder builder = null;
		try {
			HttpClient client = HttpClients.createDefault();
			RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();
			HttpPost httpPost = new HttpPost(address);
			httpPost.setConfig(requestConfig);
			List<NameValuePair> parameters = new ArrayList<NameValuePair>();
			for (Entry<String, String> entry : params.entrySet()) {
				parameters.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
			}
			UrlEncodedFormEntity encodedFormEntity = new UrlEncodedFormEntity(parameters,"UTF-8");
			httpPost.setEntity(encodedFormEntity);			
			if(head!=null){
				for (Entry<String, String> entry : head.entrySet()) {
					httpPost.setHeader(entry.getKey(), entry.getValue());
				}
			}			
			HttpResponse response = client.execute(httpPost);
			builder = new StringBuilder();
			builder.append(new String(getByte(response.getEntity().getContent()),"UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (UnsupportedOperationException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return builder.toString();
	}

	public static String HttpsClientGet(String address,Map<String,String> head,Map<String,String> params) {
		StringBuilder builder = new StringBuilder();
		try {
			if(params!=null){
				List<NameValuePair> param = new ArrayList<NameValuePair>();
				for (Entry<String, String> entry : params.entrySet()) {
					param.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
				}
				UrlEncodedFormEntity encodedFormEntity = new UrlEncodedFormEntity(param,"UTF-8");
				String str = EntityUtils.toString(encodedFormEntity);
				address = address+"?"+str;
			}
			HttpClient client = HttpClients.createDefault();
			HttpGet httpGet = new HttpGet(address);
			if(head!=null){
				for (Entry<String, String> entry : head.entrySet()) {
					httpGet.setHeader(entry.getKey(), entry.getValue());
				}
			}
			HttpResponse response = client.execute(httpGet);
			builder = new StringBuilder();
			builder.append(new String(getByte(response.getEntity().getContent()),"UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (UnsupportedOperationException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return builder.toString();
	}	
	
	public static byte[] getByte(InputStream inputStream) throws Exception{
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
		int len = 0;
		byte[] b = new byte[1024];
		while ((len = inputStream.read(b))!=-1) {
			byteArrayOutputStream.write(b, 0, len);
			byteArrayOutputStream.flush();
		}
		inputStream.close();
		byteArrayOutputStream.close();
		return byteArrayOutputStream.toByteArray();
	}  
	
	public static void main(String[] args) {
	      try {
			String nickName = "U+0038 U+20E3";  
			  
			    byte[] t = nickName.substring(0, 1).getBytes("UTF-8");  
			    for (byte tt : t) {  
			        System.out.println(tt);  
			    }  
			    System.out.println("====================");  
			    byte[] t1 = nickName.getBytes("UTF-8");  
			    for (int i = 0; i < t1.length;) {  
			        byte tt = t1[i];  
			        if (CharUtils.isAscii((char) tt)) {  
			            byte[] ba = new byte[1];  
			            ba[0] = tt;  
			            i++;  
			            String result = new String(ba);  
			            System.out.println("1个字节的字符");  
			            System.out.println("字符为：" + result);  
			        }  
			        if ((tt & 0xE0) == 0xC0) {  
			            byte[] ba = new byte[2];  
			            ba[0] = tt;  
			            ba[1] = t1[i+1];  
			            i++;  
			            i++;  
			            String result = new String(ba);  
			            System.out.println("2个字节的字符");  
			            System.out.println("字符为：" + result);  
			        }  
			        if ((tt & 0xF0) == 0xE0) {  
			            byte[] ba = new byte[3];  
			            ba[0] = tt;  
			            ba[1] = t1[i+1];  
			            ba[2] = t1[i+2];  
			            i++;  
			            i++;  
			            i++;  
			            String result = new String(ba);  
			            System.out.println("3个字节的字符");  
			            System.out.println("字符为：" + result);  
			        }  
			        if ((tt & 0xF8) == 0xF0) {  
			            byte[] ba = new byte[4];  
			            ba[0] = tt;  
			            ba[1] = t1[i+1];  
			            ba[2] = t1[i+2];  
			            ba[3] = t1[i+3];  
			            i++;  
			            i++;  
			            i++;  
			            i++;  
			            String result = new String(ba);  
			            System.out.println("4个字节的字符");  
			            System.out.println("字符为：" + result);  
			        }  
			    }
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}  
	 }  		
}
